﻿// This source file is part of the atomdb project
// 
// Copyright (c) 2017 - 2022 pulsarware, All rights reserved.
// Copyright (c) 2017 - 2022 polarboy <polarboy@163.com>
// 
// See https://atomdb.com/LICENSE.txt for license information
// 
// Created by polarboy on 2023/12/01.

using System.CommandLine;
using System.CommandLine.Binding;
using System.Diagnostics.CodeAnalysis;

namespace Pulsarware.ATOMDB.Packager.Command;

public class CommandOptionBinder : BinderBase<Config>
{
   private readonly Config _config;
   [AllowNull]
   public Option<DirectoryInfo> QtDirOption { get; init; }
   
   [AllowNull]
   public Option<Version?> QtVersionOption { get; init; }
   
   [AllowNull]
   public Argument<DirectoryInfo> SourceDirArg { get; init; }
   
   [AllowNull]
   public Option<DirectoryInfo> BuildDirOption { get; init; }
   
   [AllowNull]
   public Option<int> JobsOption { get; init; }

   [AllowNull]
   public Option<Version?> MiniCMakeVersionOption { get; init; }

   [AllowNull]
   public Option<Version> ReleaseVersionOption { get; init; }
   
   [AllowNull] 
   public Option<bool> UseNinjaOption { get; init; }

   [AllowNull] 
   public Option<bool> ShowBuildTimeOption { get; init; }
   
   [AllowNull]
   public Option<bool> AppendVersionToPackageFilenameOption { get; init; }
   
   [AllowNull]
   public Option<bool> AppendDateToPackageFilenameOption { get; init; }

   public CommandOptionBinder(Config config)
   {
      this._config = config;
   }
   
   protected override Config GetBoundValue(BindingContext bindingContext)
   {
      _config.Jobs = bindingContext.ParseResult.GetValueForOption(JobsOption);
      _config.BuildDir = bindingContext.ParseResult.GetValueForOption(BuildDirOption);
      _config.SourceDir = bindingContext.ParseResult.GetValueForArgument(SourceDirArg);
      _config.QtDir = bindingContext.ParseResult.GetValueForOption(QtDirOption);
      _config.QtVersion = bindingContext.ParseResult.GetValueForOption(QtVersionOption);
      _config.ReleaseVersion = bindingContext.ParseResult.GetValueForOption(ReleaseVersionOption);
      _config.MiniCMakeVersion = bindingContext.ParseResult.GetValueForOption(MiniCMakeVersionOption);
      _config.UseNinja = bindingContext.ParseResult.GetValueForOption(UseNinjaOption);
      _config.ShowBuildTime = bindingContext.ParseResult.GetValueForOption(ShowBuildTimeOption);
      _config.AppendDateToPackageFilename = bindingContext.ParseResult.GetValueForOption(AppendDateToPackageFilenameOption);
      _config.AppendVersionToPackageFilename = bindingContext.ParseResult.GetValueForOption(AppendVersionToPackageFilenameOption);
      return _config;
   }
}